package org.hive.testserver.domain.model;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;

public class ProjectPropertiesAccessor {

	public static final String CONTEXT_MAPPING_ROOT = "context.mapping";
	public static final String CONTEXT_RUNCONTEXT_HIGHLIGHT_ROOT = "context.runContext.highlight";
	
	private Map<String, String> properties;
	
	public ProjectPropertiesAccessor(Map<String,String> properties) {
		super();
		this.properties = properties;
	}
	
	public String contextMapping(String key) {
		return StringUtils.defaultIfEmpty(getProperty(CONTEXT_MAPPING_ROOT, key), key);
	}
	
	public void addContextMapping(String key, String displayKey) {
		properties.put(with(CONTEXT_MAPPING_ROOT, key), displayKey);
	}
	
	public boolean shouldHighlightRunContext(String key) {
		return StringUtils.isNotBlank(getProperty(CONTEXT_RUNCONTEXT_HIGHLIGHT_ROOT, key));
	}

	public void setProperty(String key, String value) {
		properties.put(key, value);
	}
	
	public String getProperty(String parentKey, String key) {
		return getProperty(with(parentKey, key));
	}
	
	public String getProperty(String key) {
		return properties.get(key);
	}
	
	private String with(String parent, String key) {
		return parent+"."+key;
	}

	public Map<String, String> propertiesCopy() {
		return new HashMap<String,String>(properties);
	}

	public void removeProperty(String keyToDelete) {
		properties.remove(keyToDelete);
	}
}
